package cn.jiemusic.controller;

import cn.jiemusic.common.R;
import cn.jiemusic.domain.po.Music;
import cn.jiemusic.domain.po.UserLike;
import cn.jiemusic.service.UserLikeService;
import cn.jiemusic.utils.JWTUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/user-like")
@Slf4j
public class UserLikeController {
    @Autowired
    private UserLikeService userLikeService;

    @PostMapping("/{sid}")
    public R<String> like(HttpServletRequest req, @PathVariable String sid) {
        String uid = JWTUtils.getIdByRequest(req);
        userLikeService.addLikeSong(uid, sid);
        return R.success("收藏成功");
    }

    @DeleteMapping("/{sid}")
    public R<String> delSong(HttpServletRequest req, @PathVariable String sid) {
        String uid = JWTUtils.getIdByRequest(req);
        userLikeService.delSong(uid, sid);
        return R.success("已取消收藏");
    }
}
